﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.Sql;
using System.Data.SqlClient;
using com.codebump;
using System.Data;

public partial class NAPower_Default : System.Web.UI.Page
{
    DataAccess App;
    bool SearchZip;
    bool IsOutbound;
    int Sender;
    bool ScheduleCallBack;
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (!IsPostBack)
            {
                if (Request.QueryString.HasKeys())
                {
                    if (Request.QueryString["listid"] != String.Empty)
                        Session["listid"] = Request.QueryString["listid"];
                    else
                        Session["listid"] = 1;


                    if (Request.QueryString["dnis"] != null)
                    {
                        Session["dnis"] = Request.QueryString["dnis"];
                    }
                    else
                    {
                        Session["dnis"] = "9999999999";
                    }

                    Session["servername"] = Request.QueryString["servername"];
                    Session["projectname"] = Request.QueryString["projectname"];
                    Session["campaignname"] = Request.QueryString["campaignname"];
                    Session["agentid"] = Request.QueryString["agentid"];
                    Session["agentfirst"] = Request.QueryString["agentfirst"];
                    Session["agentlast"] = Request.QueryString["agentlast"];
                    Session["isoutbound"] = Request.QueryString["isoutbound"];
                    Session["leadid"] = Request.QueryString["leadid"];

                }
                SearchZip = false;
                App = new DataAccess();
                Session["App"] = App;
                if (Convert.ToInt32((string)Session["leadid"]) > 0)
                { IsOutbound = true; } 
                else
                { IsOutbound = false; }

                if (IsOutbound == true)
                {
                    lblLeadFirstName.Text = App.OBGetOldCallData("FirstName").ToString();
                    lblLeadFirstName0.Text = App.OBGetOldCallData("FirstName").ToString();
                    App.PutCallData("IsOutbound", "Yes");
                    App.PutCallData("LeadID", (string)Session["leadid"]);
                    ddlResBus.SelectedValue = App.OBGetOldCallData("ResOrBus").ToString();
                    tbFirstName.Text = App.OBGetOldCallData("FirstName").ToString();
                    tbLastName.Text = App.OBGetOldCallData("LastName").ToString();
                    tbPriPhone.Text = App.OBGetOldCallData("Phone").ToString();
                    tbSecPhone.Text = App.OBGetOldCallData("AltPhone").ToString();
                    tbEmail.Text = App.OBGetOldCallData("Email").ToString();
                    tbHStreet.Text = App.OBGetOldCallData("BillAddress").ToString();
                    tbZip.Text = App.OBGetOldCallData("BillZip").ToString();
                    btnSearchZip_Click(null, null);//Run the SearchZip Function.
                    SearchZip = true;
                    
                    ddlState.SelectedValue = App.OBGetOldCallData("BillState");
                    ddlCountry.SelectedIndex = 0;
                    tbMStreet.Text = App.OBGetOldCallData("OtherAddress").ToString();
                    tbMCity.Text = App.OBGetOldCallData("OtherCity").ToString();
                    tbMState.Text = App.OBGetOldCallData("OtherState").ToString();
                    tbMZip.Text = App.OBGetOldCallData("OtherZip").ToString();
                    WebWizard.ActiveStepIndex = WebWizard.WizardSteps.IndexOf(this.Outbound);
                }
                else
                {
                    App.PutCallData("IsOutbound", "No");
                    WebWizard.ActiveStepIndex = 2;
                }
                ScheduleCallBack = false;
                Session["ScheduleCallBack"] = ScheduleCallBack;
                Session["SearchZip"] = SearchZip;
                App.PutCallData("ScriptStart", System.DateTime.Now.ToString());
                App.PutCallData("AgentFirst", Session["agentfirst"].ToString());
                App.PutCallData("AgentLast", Session["agentlast"].ToString());
                tbListid.Text = App.GetCallData("enterpriselistid");
                App.CommitCallData();

                try
                {
                    DataTable dtUserCodes = App.GetUsercodes();
                    for (int r = 0; r < dtUserCodes.Rows.Count; r++)
                    {
                        if (IsOutbound)
                        {
                            if (dtUserCodes.Rows[r]["GroupType"].ToString() == "Inbound")
                            {
                                dtUserCodes.Rows[r].Delete();
                            }
                        }
                        else
                        {
                            if (dtUserCodes.Rows[r]["GroupType"].ToString() == "Outbound")
                            {
                                dtUserCodes.Rows[r].Delete();
                            }
                        }
                    }
                    ddlDispo.DataSource = dtUserCodes;
                    ddlDispo.DataTextField = dtUserCodes.Columns["textField"].ColumnName.ToString();
                    ddlDispo.DataValueField = dtUserCodes.Columns["usercode"].ColumnName.ToString();
                    ddlDispo.DataBind();
                    ddlDispo.Items.Insert(0, new ListItem("", ""));
                }
                catch
                {
                    ddlDispo.Items.Insert(0, new ListItem("Unable to get dispos", "Unable to get dispos"));
                }

            }
            else
            {
                if (IsOutbound == true)
                {
                    ddlCity.SelectedValue = App.OBGetOldCallData("BillCity");
                }
                App = (DataAccess)Session["App"];
                SearchZip = (bool)Session["SearchZip"];
                ScheduleCallBack = (bool)Session["ScheduleCallBack"];
                if (Convert.ToInt32((string)Session["leadid"]) > 0)
                { IsOutbound = true; } //if there is no leadid then its inbound
                else
                { IsOutbound = false; } //if there is a leadid then its outbound
            }
        }
        catch (Exception ex)
        {
            lblException.Visible = true;
            lblException.Text = "CONTACT IT/SUPERVISOR with the following information or screenshot:" + ex.ToString();
        }
    }

    //POST LOGIC - For Step or Start pages
    protected void WebWizard_NextButtonClick(object sender, WizardNavigationEventArgs e)
    {
        try
        {
            int page = WebWizard.ActiveStepIndex;
            

            if (page == WebWizard.WizardSteps.IndexOf(this.Greeting))
            {
                if (ddlBillHandy.SelectedIndex == 0 || ddlResBus.SelectedIndex == 0)
                {
                    pnlAddressData.Visible = false;
                }
                else
                {
                    if (ddlState.SelectedValue.ToString() == "NY")
                    {
                        WebWizard.ActiveStepIndex = WebWizard.WizardSteps.IndexOf(this.NewYork);
                    }
                    else
                    {
                        if (ddlBillHandy.SelectedValue.ToString() == "Yes")
                        {
                            WebWizard.ActiveStepIndex = WebWizard.WizardSteps.IndexOf(this.Yes);
                        }
                        else
                        {
                            WebWizard.ActiveStepIndex = WebWizard.WizardSteps.IndexOf(this.No);
                        }
                    }
                }
                validPrimaryPhone.Text = "Must Enter a Primary Phone Number";
                return;
            }

            //if (page == WebWizard.WizardSteps.IndexOf(this.Yes))
            //{

            //    WebWizard.ActiveStepIndex = WebWizard.WizardSteps.IndexOf(this.No);
            //    return;
            //}

            //if (page == WebWizard.WizardSteps.IndexOf(this.No))
            //{
            //    WebWizard.ActiveStepIndex = WebWizard.WizardSteps.IndexOf(this.NewYork);

            //    return;
            //}
            //if (page == WebWizard.WizardSteps.IndexOf(this.NewYork))
            //{

            //    return;
            //}
            //if (page == WebWizard.WizardSteps.IndexOf(this.Outbound))
            //{

            //    return;
            //}
            //if (page == WebWizard.WizardSteps.IndexOf(this.Rebuttals))
            //{
            //    WebWizard.ActiveStepIndex = WebWizard.WizardSteps.IndexOf(this.Rebuttals);
            //    return;
            //}
            //if (page == WebWizard.WizardSteps.IndexOf(this.FAQ))
            //{
            //    WebWizard.ActiveStepIndex = WebWizard.WizardSteps.IndexOf(this.FAQ);
            //    return;
            //}
            //if (page == WebWizard.WizardSteps.IndexOf(this.Disposition))
            //{

            //    return;
            //}
        }
        catch (Exception ex)
        {
            lblException.Visible = true;
            lblException.Text = ex.ToString();
        }


    }

    //POST LOGIC for finish pages
    protected void WebWizard_FinishButtonClick(object sender, WizardNavigationEventArgs e)
    {
        try
        {
            int page = WebWizard.ActiveStepIndex;


            //if (page == WebWizard.WizardSteps.IndexOf(this.Greeting))
            //{

            //    return;
            //}

            if (page == WebWizard.WizardSteps.IndexOf(this.Yes))
            {
                Sender = 3;
                if (ddlPassTpvInbound.SelectedIndex == 1)
                {
                    App.PutCallData("Disposition", "SC");
                    App.PutCallData("webusercode", "TP");
                }
                if (ddlPassTpvInbound.SelectedIndex == 2)
                {
                    App.PutCallData("Disposition", "SC");
                    App.PutCallData("webusercode", "TF");
                }
                WebWizard.ActiveStepIndex = WebWizard.WizardSteps.IndexOf(this.Disposition);
                return;
            }

            if (page == WebWizard.WizardSteps.IndexOf(this.No))
            {
                Sender = 4;
                if (ScheduleCallBack)
                {
                    App.PutCallData("Disposition", "SC");
                    App.PutCallData("webusercode", "C1");
                }
                else
                {
                    App.PutCallData("Disposition", "SR");
                    App.PutCallData("webusercode", "C2");
                }
                WebWizard.ActiveStepIndex = WebWizard.WizardSteps.IndexOf(this.Disposition);
                return;
            }
            if (page == WebWizard.WizardSteps.IndexOf(this.NewYork))
            {
                Sender = 5;
                if (ddlBestTime0.SelectedIndex != 0 && ddlBestTime0.SelectedIndex != 4)
                {
                    App.PutCallData("Disposition", "SC");
                    App.PutCallData("webusercode", "C3");
                }
                else
                {
                    App.PutCallData("Disposition", "SR");
                    App.PutCallData("webusercode", "C4");
                }
                WebWizard.ActiveStepIndex = WebWizard.WizardSteps.IndexOf(this.Disposition);
                return;
            }
            if (page == WebWizard.WizardSteps.IndexOf(this.Outbound))
            {
                Sender = 6;
                if (ScheduleCallBack)
                {
                    App.PutCallData("Disposition", "SC");
                    App.PutCallData("webusercode", "O1");
                }
                else if (!ScheduleCallBack && ddlPassTpvOutbound.SelectedIndex == 0)
                {
                    App.PutCallData("Disposition", "SR");
                    App.PutCallData("webusercode", "O2");
                    App.OBFinalizeLead("O2");
                }
                else if (ddlPassTpvOutbound.SelectedIndex == 1 && !ScheduleCallBack)
                {
                    App.PutCallData("Disposition", "SC");
                    App.PutCallData("webusercode", "OP");
                    App.OBFinalizeLead("OP");
                }
                else if (ddlPassTpvOutbound.SelectedIndex == 2 && !ScheduleCallBack)
                {
                    App.PutCallData("Disposition", "SR");
                    App.PutCallData("webusercode", "OF");
                    App.OBFinalizeLead("OF");
                }
                WebWizard.ActiveStepIndex = WebWizard.WizardSteps.IndexOf(this.Disposition);
                return;
            }
            //if (page == WebWizard.WizardSteps.IndexOf(this.Rebuttals))
            //{
            //    WebWizard.ActiveStepIndex = WebWizard.WizardSteps.IndexOf(this.Disposition);
            //    return;
            //}
            //if (page == WebWizard.WizardSteps.IndexOf(this.FAQ))
            //{
            //    WebWizard.ActiveStepIndex = WebWizard.WizardSteps.IndexOf(this.Disposition);
            //    return;
            //}
            //if (page == WebWizard.WizardSteps.IndexOf(this.Disposition))
            //{

            //    return;
            //}
        }
        catch (Exception ex)
        {
            lblException.Visible = true;
            lblException.Text = ex.ToString();
        }


    }

    //PRE-LOGIC
    protected void WebWizard_ActiveStepChanged(object sender, EventArgs e)
    {

        if (WebWizard.ActiveStep.ID.ToString() == "Greeting")
        {
            pnlAddressData.Visible = true;
            if (IsOutbound == false)
            {
                Panel3.Visible = false;
                if (chkShowAddress.Checked)
                {
                    pnlAddressData.Visible = true;
                }
                else
                {
                    pnlAddressData.Visible = false;
                }
                return;
            }
            else
            {
                WebWizard.ActiveStepIndex = 6;
            }
        }

        ////////////////////////////////////////////////////////////////////////////////////YES
        if (WebWizard.ActiveStep.ID.ToString() == "Yes")
        {
            if (IsOutbound == false)
            {
                Panel3.Visible = false;
                if (ddlBillHandy.SelectedIndex == 0 || ddlResBus.SelectedIndex == 0 || ddlBillHandy.SelectedIndex == 2 || SearchZip == false)
                {
                    if (SearchZip)
                    {
                        if (ddlState.SelectedValue.ToString() == "NY")
                        {
                            WebWizard.ActiveStepIndex = 5;
                        }
                        else
                        {
                            if (ddlBillHandy.SelectedIndex == 1)
                            {
                                WebWizard.ActiveStepIndex = 3;
                            }
                            else if (ddlBillHandy.SelectedIndex == 2)
                            {
                                WebWizard.ActiveStepIndex = 4;
                            }
                            else if (ddlBillHandy.SelectedIndex == 0)
                            {
                                WebWizard.ActiveStepIndex = 2;
                            }
                        }
                    }
                    else
                    { WebWizard.ActiveStepIndex = 2; }
                }
                else
                {
                    if (ddlState.SelectedValue.ToString() == "NY")
                    {
                        WebWizard.ActiveStepIndex = 5;
                    }
                    else
                    {
                        //OK
                    }
                }
                return;
            }
            else
            {
                WebWizard.ActiveStepIndex = 6;
            }
        }

        ////////////////////////////////////////////////////////////////////////////////////NO
        if (WebWizard.ActiveStep.ID.ToString() == "No")
        {
            Panel3.Visible = true;
            if (IsOutbound == false)
            {
                Panel3.Visible = true;
                if (chkShowAddress.Checked)
                {
                    pnlAddressData.Visible = true;
                }
                else
                {
                    pnlAddressData.Visible = false;
                }
                if (ddlBillHandy.SelectedIndex == 0 || ddlResBus.SelectedIndex == 0 || ddlBillHandy.SelectedIndex == 1 || SearchZip == false)
                {
                    if (SearchZip)
                    {
                        if (ddlState.SelectedValue.ToString() == "NY")
                        {
                            WebWizard.ActiveStepIndex = 5;
                        }
                        else
                        {
                            if (ddlBillHandy.SelectedIndex == 1)
                            {
                                WebWizard.ActiveStepIndex = 3;
                            }
                            else if (ddlBillHandy.SelectedIndex == 2)
                            {
                                WebWizard.ActiveStepIndex = 4;
                            }
                            else if (ddlBillHandy.SelectedIndex == 0)
                            {
                                WebWizard.ActiveStepIndex = 2;
                            }
                        }
                    }
                    else
                    { WebWizard.ActiveStepIndex = 2; }
                }
                else
                {
                    Panel3.Visible = true;
                    if (ddlState.SelectedValue.ToString() == "NY")
                    {
                        WebWizard.ActiveStepIndex = 5;
                    }
                    else
                    {
                        //OK
                    }
                }
                return;
            }
            else
            {
                WebWizard.ActiveStepIndex = 6;
            }
        }

        ////////////////////////////////////////////////////////////////////////////////////NEWYORK
        if (WebWizard.ActiveStep.ID.ToString() == "NewYork")
        {
            
            if (IsOutbound == false)
            {
                Panel3.Visible = false;
                if (chkShowAddress.Checked)
                {
                    pnlAddressData.Visible = true;
                }
                else
                {
                    pnlAddressData.Visible = false;
                }
                if (ddlState.SelectedValue.ToString() == "NY" || SearchZip == false)
                {
                    if (SearchZip == false)
                    {
                        WebWizard.ActiveStepIndex = 2;
                    }
                    else
                    {
                    }
                }
                else
                {
                    if (SearchZip)
                    {
                        if (ddlState.SelectedValue.ToString() == "NY")
                        {
                            WebWizard.ActiveStepIndex = 5;
                        }
                        else
                        {
                            if (ddlBillHandy.SelectedIndex == 1)
                            {
                                WebWizard.ActiveStepIndex = 3;
                            }
                            else if (ddlBillHandy.SelectedIndex == 2)
                            {
                                WebWizard.ActiveStepIndex = 4;
                            }
                            else if (ddlBillHandy.SelectedIndex == 0)
                            {
                                WebWizard.ActiveStepIndex = 2;
                            }
                        }
                    }
                    else
                    { WebWizard.ActiveStepIndex = 2; }
                }
                return;
            }
            else
            {
                WebWizard.ActiveStepIndex = 6;
            }
        }
        
        ////////////////////////////////////////////////////////////////////////////////////OUTBOUND
        if (WebWizard.ActiveStep.ID.ToString() == "Outbound")
        {

            
            Panel3.Visible = true;
            if (IsOutbound==true)
            {
                
                if (ddlState.SelectedValue.ToString() == "NY")
                {
                    WebWizard.ActiveStepIndex = 5;
                }
                else
                {
                    //OK
                }    
            }
            else
            {
                if (SearchZip)
                {
                    if (ddlState.SelectedValue.ToString() == "NY")
                    {
                        WebWizard.ActiveStepIndex = 5;
                    }
                    else
                    {
                        if (ddlBillHandy.SelectedIndex == 1)
                        {
                            WebWizard.ActiveStepIndex = 3;
                        }
                        else if (ddlBillHandy.SelectedIndex == 2)
                        {
                            WebWizard.ActiveStepIndex = 4;
                        }
                        else if (ddlBillHandy.SelectedIndex == 0)
                        {
                            WebWizard.ActiveStepIndex = 2;
                        }
                    }
                }
                else
                { WebWizard.ActiveStepIndex = 2; }
            }
            return;
        }
        if (WebWizard.ActiveStep.ID.ToString() == "Rebuttals")
        {
            return;
        }
        if (WebWizard.ActiveStep.ID.ToString() == "FAQ")
        {
            return;
        }

        ////////////////////////////////////////////////////////////////////////////////////DISPOSITION
        if (WebWizard.ActiveStep.ID.ToString() == "Disposition")
        {
            validPrimaryPhone.Visible = false;
            Panel3.Visible = false;
            try
            {
                lblNonOrderDispo.Visible = false;
                if (ddlBillHandy.SelectedIndex == 0 || ddlResBus.SelectedIndex == 0 || SearchZip == false || (ddlPassTpvInbound.SelectedIndex == 0 && ddlPassTpvOutbound.SelectedIndex == 0 && (ddlBillHandy.SelectedIndex != 2 && ddlState.SelectedValue.ToString() != "NY")))
                {
                    if (IsOutbound == true)
                    {
                        WebWizard.ActiveStepIndex = 6;
                    }
                    if (IsOutbound == false)
                    {
                        if (ddlPassTpvInbound.SelectedIndex == 0 && ddlPassTpvOutbound.SelectedIndex == 0 && (ddlBillHandy.SelectedIndex != 2 && ddlState.SelectedValue.ToString() != "NY"))
                        {
                            lblPassTPVerror.Visible = true;
                            lblPassTPVerror0.Visible = true;
                        }
                        if (SearchZip == false)
                        {
                            btnSearchZip.BackColor = System.Drawing.Color.Red;
                            
                        }
                        if (ddlResBus.SelectedIndex == 0)
                        {
                            ddlResBus.BackColor = System.Drawing.Color.Red;
                        }
                        if (ddlBillHandy.SelectedIndex == 0)
                        {
                            ddlBillHandy.BackColor = System.Drawing.Color.Red;
                                
                        }
                        WebWizard.ActiveStepIndex = Sender;
                    }
                }
                else
                {
                    App.PutCallData("FirstName", tbFirstName.Text.Replace(",", ""));
                    App.PutCallData("LastName", tbLastName.Text.Replace(",", ""));
                    App.PutCallData("Phone", tbPriPhone.Text.Replace(",", ""));
                    App.PutCallData("AltPhone", tbSecPhone.Text.Replace(",", ""));
                    App.PutCallData("Email", tbEmail.Text.Replace(",", ""));
                    App.PutCallData("BillAddress", tbHStreet.Text.Replace(",", ""));
                    //if (ddlCity.Enabled == true)
                    App.PutCallData("BillCity", ddlCity.SelectedItem.ToString().Replace(",", ""));
                    App.PutCallData("BillState", ddlState.SelectedValue.ToString().Replace(",", ""));
                    App.PutCallData("BillZip", tbZip.Text);
                    App.PutCallData("OtherAddress", tbMStreet.Text.Replace(",", ""));
                    App.PutCallData("OtherCity", tbMCity.Text.Replace(",", ""));
                    App.PutCallData("OtherState", tbMState.Text.Replace(",", ""));
                    App.PutCallData("OtherZip", tbMZip.Text.Replace(",", ""));
                    App.PutCallData("BillHandy", ddlBillHandy.SelectedItem.ToString().Replace(",", ""));
                    App.PutCallData("ResOrBus", ddlResBus.SelectedItem.ToString().Replace(",", ""));

                    if (ddlBillHandy.SelectedIndex == 1 && ddlState.SelectedValue.ToString() != "NY")
                    {
                        if (IsOutbound == true)
                        {
                            App.PutCallData("PassTPV", ddlPassTpvOutbound.SelectedItem.ToString().Replace(",", ""));
                        }
                        else
                        {
                            App.PutCallData("PassTPV", ddlPassTpvInbound.SelectedItem.ToString().Replace(",", ""));
                        }
                    }
                    else
                    {
                        if (ddlState.SelectedValue == "NY")
                        {
                            App.PutCallData("BestTimeOfDay", ddlBestTime0.SelectedValue.ToString());
                        }
                        else
                        {
                            App.PutCallData("BestTimeOfDay", "N/A");
                        }
                        App.PutCallData("PassTPV", "N/A");

                    }

                    if (calBestDay.SelectedDate >= DateTime.Today && ddlBestTime.SelectedIndex != 0)
                    {
                        /////////////////////////////////////////////////////////////
                    }
                    else
                    {
                        App.PutCallData("BestDay", "1/1/1900");
                        if (ddlState.SelectedValue == "NY")
                        {
                            App.PutCallData("BestTimeOfDay", ddlBestTime0.SelectedValue.ToString());
                        }
                        else
                        {
                            App.PutCallData("BestTimeOfDay", "N/A");
                        }
                    }

                    App.CommitCallData();
                    Response.Redirect("../DispositionComplete.aspx");
                }
                 

            }
            catch (Exception ex)
            {
                lblException.Visible = true;
                lblException.Text = ex.ToString();
            }
        }

    }

    ////////////////////////////////////////////////////////////////////////////////////END OF PRE-LOGIC  START OF MISC FUNCTIONS
    protected void chkViewAddress_CheckedChanged(object sender, EventArgs e)
    {

    }
    protected void chkSameAs_CheckedChanged(object sender, EventArgs e)
    {
        try
        {
            if (chkSameAs.Checked == true)
            {
                tbMStreet.Text = tbHStreet.Text;
                //tbMStreet.Enabled = false;
                tbMCity.Text = ddlCity.SelectedItem.ToString();
                //tbMCity.Enabled = false;
                tbMState.Text = ddlState.SelectedItem.ToString();
                //tbMState.Enabled = false;
                tbMZip.Text = tbZip.Text;
                //tbMZip.Enabled = false;
            }
            else
            {
                tbMStreet.Text = "";
                tbMCity.Text = "";
                tbMState.Text = "";
                tbMZip.Text = "";
            }
        }
        catch
        {
            //Do Nothing
        }


    }
 
    protected void btnSearchZip_Click(object sender, EventArgs e)
    {

        ddlCity.Items.Clear();
        ddlCity.Enabled = true;
        Session["SearchZip"] = true;

        if (System.Text.RegularExpressions.Regex.IsMatch(tbZip.Text.ToUpper(), @"(^\d{5}$)|(^[ABCEGHJKLMNPRSTVXY]{1}\d{1}[A-Z]{1} *\d{1}[A-Z]{1}\d{1}$)"))
        {
            try
            {

                GeoPlaces g = new GeoPlaces();

                AuthenticationHeader authHeader = new AuthenticationHeader();
                authHeader.SessionID = "6JV2ZA4lgG1YRR+HG+JU27QWk9zI3rpRWY2iG2mzNPcdieEQXfQv0OUY0EZ+pOTxhwI1NCuF7b2oY+U/bozy0mhjFHmpaXvb";
                g.AuthenticationHeaderValue = authHeader;

                //GeoPlaceDistance[] places = g.GetPlacesWithin("Los Angeles", "CA", 10, GeoPlaceType.ZipCode);
                GeoPlaceDistance[] places = g.GetPlacesInside(tbZip.Text, "");

                for (int i = 0; i < places.Length; i++)
                {
                    GeoPlaceDistance place = places[i];
                    ListItem li = new ListItem(place.ToPlace, place.ToState + "," + place.ToPlace);
                    ddlCity.Items.Add(li);
                }


                ddlState.Items.Clear();
                ddlState.Items.Add(ddlCity.SelectedItem.Value.Split(",".ToCharArray())[0]);

                //ddlCity.SelectedIndex = 0;

                if (System.Text.RegularExpressions.Regex.IsMatch(tbZip.Text.ToUpper(), @"(^[ABCEGHJKLMNPRSTVXY]{1}\d{1}[A-Z]{1} *\d{1}[A-Z]{1}\d{1}$)"))
                {
                    ddlCountry.SelectedValue = "CANADA";
                }
                else
                {
                    ddlCountry.SelectedValue = "USA";
                }

                if (ddlCity.Items.Count == 1)
                {
                    ddlCity.Enabled = false;

                    //tbState.Text += ddlCity.SelectedItem.Value.ToString();
                }
                else if (ddlCity.Items.Count <= 0)
                {
                    ddlCity.Items.Add("No Cities Found");
                    ddlCity.Enabled = false;
                }
                else
                {
                }
            }
            catch
            {
                ddlCity.Items.Add("No Cities Found");
                ddlCity.Enabled = false;
            }
        }
        else
        {
            ddlCity.Items.Add("Invalid Zip");
            ddlCity.Enabled = false;
        }
        if (ddlCity.Enabled == true)
        {
            ddlCity.Items.Insert(0, "Select A City");
            ddlCity.SelectedIndex = 0;
        }
    }
    protected void WebWizard_PreviousButtonClick(object sender, WizardNavigationEventArgs e)
    {
        validPrimaryPhone.Visible = false;
    }

    protected void calBestDay_SelectionChanged(object sender, EventArgs e)
    {
        lblDate.Text = calBestDay.SelectedDate.ToString("D");
    }
    protected void ddlBestTime_SelectedIndexChanged(object sender, EventArgs e)
    {
        lblBestTime.Text = ddlBestTime.SelectedValue.ToString();
    }
    protected void chkShowAddress_CheckedChanged(object sender, EventArgs e)
    {
        if (chkShowAddress.Checked)
        {
            pnlAddressData.Visible = true;
        }
        else
        {
            pnlAddressData.Visible = false;
        }
    }
    protected void cmdIntitiateTPV_Click(object sender, EventArgs e)
    {
        //Nothing Yet
    }
    protected void btnCallBack_Click(object sender, EventArgs e)
    {
        if (String.IsNullOrEmpty(tbPriPhone.Text) || tbPriPhone.Text.Length != 10)
        {
            lblCallBackNoPhone.Visible = true;
            ScheduleCallBack = false;
        }
        else
        {
            Session["ScheduleCallBack"] = true;
            ScheduleCallBack = true;

            App.PutCallData("BestDay", calBestDay.SelectedDate.ToShortDateString());
            App.PutCallData("BestTimeOfDay", ddlBestTime.SelectedItem.ToString());
            string BestTime = "";
            switch (ddlBestTime.SelectedIndex)
            {
                case 1:
                    BestTime = "7:00:00 AM";
                    break;
                case 2:
                    BestTime = "11:00:00 AM";
                    break;
                case 3:
                    BestTime = "4:00:00 PM";
                    break;
                default:
                    BestTime = "7:00:00 AM";
                    break;
            }
            if (IsOutbound)
            {
                App.OBUpdateLead(Convert.ToInt32(App.OBGetOldCallData("enterpriselistid")), calBestDay.SelectedDate.ToShortDateString() + " " + BestTime, tbPriPhone.Text, "O1");
            }
            else
            {
                App.OBLeadRemove(Convert.ToInt32(App.OBGetOldCallData("enterpriselistid")));
                App.OBLeadInsert(Convert.ToInt32(App.GetCallData("enterpriselistid")), calBestDay.SelectedDate.ToShortDateString() + " " + BestTime, tbPriPhone.Text, App.GetCallData("DNIS").ToString());
            }
        }
        
    }
    protected void ddlDispo_SelectedIndexChanged(object sender, EventArgs e)
    {
        App.PutCallData("webusercode", ddlDispo.SelectedItem.Value);



        if (ddlDispo.SelectedIndex != 0)
        {
            btnDispo.Visible = true;
        }
        else
        {
            btnDispo.Visible = false;
        }
    }
    protected void btnDispo_Click(object sender, EventArgs e)
    {
        if (IsOutbound)
        {
            if (ddlDispo.SelectedValue.ToString() == "ON")
            { App.OBFinalizeLead("ON"); }

        }

        App.CommitCallData();

        Response.Redirect("../DispositionComplete.aspx");

    }
}